

class Card(object):
    """docstring for Card"""
    def __init__(self):
        self.name = "初始步梦"
        self.attribute = {
            "smile": 4136,
            "pure": 4059,
            "cool": 4805
        }
        self.skill = {
            "trigger": {"type": "note", "number": 28, "prob": 0.39},
            "effect": {"type": "加分", "time": 3.5, "number": 118} 
        }
        self.strength = {"smile": 0, "pure": 0, "cool": 0}
        
    def calculate(self, color, config):
        # todo：有一个东西没算，是技能持续时间内再触发时不会叠加
        self.total_multiplier = config.leader_bonus * config.combo_multiplier * config.color_bonus * config.group_bonus * config.perfect_bonus

        strength_multipler = self.total_multiplier * config.combo / 80
        #self.note_strength = self.attribute[color] * 

        self.skill_strength = 0
        trigger_num = 0
        trigger_number = 0
        if self.skill["trigger"]["type"] in ["note", "combo"]:
            trigger_num = 1.0 / self.skill["trigger"]["number"] * self.skill["trigger"]["prob"] * config.combo - 0.5
            trigger_number = self.skill["trigger"]["number"]
        elif self.skill["trigger"]["type"] in ["perfect"]:
            trigger_num = 1.0 * config.perfect_rate / self.skill["trigger"]["number"] * self.skill["trigger"]["prob"] * config.combo - 0.5
            trigger_number = 1.0 * self.skill["trigger"]["number"] / config.perfect_rate
        elif self.skill["trigger"]["type"] in ["时间"]:
            trigger_num = 1.0 / self.skill["trigger"]["number"] * self.skill["trigger"]["prob"] * config.time - 0.5

        # 得分特技
        if self.skill["effect"]["type"] == "加分":
            last_time_true = self.skill["effect"]["time"]
            if self.skill["trigger"]["type"] in ["note", "combo", "perfect"]:
                # 考虑技能重叠覆盖
                last_time_true = 0
                for density in config.density_distribution.keys():
                    current_time = 0
                    current_triggers = 1
                    remaining_probs = 1
                    time_gap = trigger_number / (density * config.combo / config.time)
                    while current_triggers * time_gap < self.skill["effect"]["time"]:
                        current_time += current_triggers * time_gap * (remaining_probs * self.skill["trigger"]["prob"])
                        remaining_probs *= (1 - self.skill["trigger"]["prob"])
                        current_triggers += 1
                    current_time += self.skill["effect"]["time"] * remaining_probs
                    last_time_true += config.density_distribution[density] * current_time
            self.skill_strength += trigger_num * (config.combo / config.time) * last_time_true * self.skill["effect"]["number"]
            
        self.skill_strength /= strength_multipler
        self.note_strength = self.attribute[color]
        if self.color != color:
            self.note_strength /= config.color_bonus
        self.strength[color] = int(self.note_strength + self.skill_strength)
        return
